package com.raising.sc.controller;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class ServiceCSleuthController {

    private static final Logger LOG = Logger.getLogger(ServiceCSleuthController.class.getName());


    @Autowired
    private RestTemplate restTemplate;

    @Bean
    public RestTemplate getRestTemplate(){
        return new RestTemplate();
    }

    @RequestMapping("/hi")
    public String callHome(String str){
        LOG.log(Level.INFO, "calling trace service-C-sleuth-2-hi  ");
//        return "hi，我是sleuth-2 str = " + str;
        return restTemplate.getForObject("http://localhost:30001/hi?str=" + str, String.class);
    }

    @Bean
    public AlwaysSampler defaultSampler(){
        return new AlwaysSampler();
    }

}
